home *** CD-ROM | disk | FTP | other *** search
- /*
- ** Apple Macintosh Developer Technical Support
- **
- ** Routines demonstrating how to launch an application without a currently
- ** running application to actually call LaunchApplication().
- **
- ** by Mark Cookson, Apple Developer Technical Support
- **
- ** File: LaunchMe.c
- **
- ** Copyright ©1996 Apple Computer, Inc.
- ** All rights reserved.
- **
- ** You may incorporate this sample code into your applications without
- ** restriction, though the sample code has been provided "AS IS" and the
- ** responsibility for its operation is 100% yours. However, what you are
- ** not permitted to do is to redistribute the source as "Apple Sample
- ** Code" after having made changes. If you're going to re-distribute the
- ** source, we require that you make it clear in the source that the code
- ** was descended from Apple Sample Code, but that you've made changes.
- */
-
- #include "LaunchMe.h"
-
- static void ToolBoxInit (void)
- {
- MaxApplZone();
- MoreMasters ();
- InitGraf (&qd.thePort);
- InitFonts ();
- InitWindows ();
- InitMenus ();
- TEInit ();
- InitDialogs ((long)nil);
- InitCursor ();
- return;
- }
-
- void main (void)
- {
- MyDelayedLaunchPtr timeRecPtr;
- Handle NotificationRtnHandle;
- SFTypeList sfType = {'APPL', nil, nil, nil};
- THz ourZone;
-
- ToolBoxInit ();
-
- timeRecPtr = (MyDelayedLaunchPtr)NewPtrSys (sizeof (MyDelayedLaunchRec)); // Put our variables in the system heap
- if (timeRecPtr == nil) // We are SO out of memory!
- return; // memFullErr if this was a real function
-
- ourZone = GetZone();
- SetZone(SystemZone()); // Switch to system heap so GetResource loads the resource into the system heap
- NotificationRtnHandle = GetResource ('rsrc', 0); // Get our code resource that does the real work
- if (NotificationRtnHandle == nil || ResError ()) { // We are out of memory
- DisposePtr ((Ptr)timeRecPtr);
- return; // memFullErr if this was a real function
- }
-
- HLock(NotificationRtnHandle); // Don't nobody go nowhere
- DetachResource(NotificationRtnHandle);
- SetZone(ourZone);
-
- StandardGetFile (nil, 1, sfType, &timeRecPtr->theSFReply); // Prompt for app to launch
- if (timeRecPtr->theSFReply.sfGood != true) { // User doesn't want to launch
- DisposePtr ((Ptr)timeRecPtr);
- DisposeHandle (NotificationRtnHandle);
- return; // userCanceledErr is this was a real function
- }
-
- timeRecPtr->launchMe.launchAppSpec = &timeRecPtr->theSFReply.sfFile;
- timeRecPtr->launchMe.launchBlockID = extendedBlock;
- timeRecPtr->launchMe.launchEPBLength = extendedBlockLen;
- timeRecPtr->launchMe.launchFileFlags = nil;
- timeRecPtr->launchMe.launchControlFlags = launchContinue + launchNoFileFlags;
- timeRecPtr->launchMe.launchAppParameters = nil;
-
- timeRecPtr->theTask.tmAddr = (void *)*NotificationRtnHandle;
- timeRecPtr->theTask.tmWakeUp = 0;
- InsXTime ((QElemPtr)timeRecPtr);
- PrimeTime ((QElemPtr)timeRecPtr, kDelay);
- }